package demo1;

import java.util.Arrays;

public class Test {
    public static void bubbleSort(Comparable[] comparables){
        for (int i = 0; i < comparables.length - 1; i++){
            for(int j = 0; j < comparables.length - i - 1; j++){
                if (comparables[j].compareTo(comparables[j + 1]) > 0) {
                    Comparable comparable = comparables[j];
                    comparables[j] = comparables[j + 1];
                    comparables[j + 1] = comparable;

                }
            }
        }
    }
    public static void main(String[] args) {
        Student student1 = new Student("bit",10);
        Student student2 = new Student("hello",5);
        Student student3 = new Student("gbk", 12);

        Student[] students = new Student[3];
        students[0] = student1;
        students[1] = student2;
        students[2] = student3;
        //System.out.println();
        //System.out.println();
        NameCompare namecompare = new NameCompare();
        AgeCompare agecompare =  new AgeCompare();

        System.out.println("排序前：" + Arrays.toString(students));
        //Arrays.sort(students,namecompare);
        //Arrays.sort(students,agecompare);
        bubbleSort(students);
        System.out.println("排序后；"+ Arrays.toString(students));
    }
    public static void main1(String[] args) {
        Student student1 = new Student("bit",10);
        Student student2 = new Student("hello",5);
        Student student3 = new Student("gbk", 12);

        Student[] students = new Student[3];
        students[0] = student1;
        students[1] = student2;
        students[2] = student3;

        System.out.println("排序前：" + Arrays.toString(students));
        Arrays.sort(students);
        System.out.println("排序后；"+ Arrays.toString(students));


        //if(student1 > student2)
        if(student1.compareTo(student2) > 0){
            System.out.println("student1 > student2");
        }
        System.out.println("===================");
        NameCompare namecompare = new NameCompare();
        int i = namecompare.compare(student1, student2);
        if(i > 0){
            System.out.println("student1 > student2");
        }else{
            System.out.println("student1 <= student2");
        }
    }
}
